home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / prg_casm / wsc4c10.zip / RUNTEST.C < prev    next >
Text File  |  1996-09-09  |  3KB  |  114 lines

  1. /*** runtest ***/
  2.  
  3. #include "windows.h"
  4. #include "wsc.h"
  5. #include "wscerror.h"
  6. #include "paint.h"
  7. #include "line.h"
  8. #include "runtest.h"
  9.  
  10. extern HWND hMainWnd;
  11. extern int  OnLineFlag;
  12. extern char Temp[1024];
  13.  
  14. #define TEST_SIZE 62
  15.  
  16. /* private */
  17.  
  18. static char TestSet[TEST_SIZE+1];
  19. static int  NbrRuns = 16;
  20. static int  TestLength = 0;
  21. static int  TestRun = 0;
  22. int GetChar(int,int);
  23.  
  24. /* public */
  25.  
  26. int RunTest(int Port)
  27. {int i;
  28.  int n;
  29.  int c;
  30.  int rc;
  31.  
  32.  /* initialize */
  33.  if(TestLength==0)
  34.    {/* build TestSet[] array */
  35.     for(i=0;i<26;i++) TestSet[i] = 'A'+i;
  36.     for(i=0;i<26;i++) TestSet[26+i] = 'a'+i;
  37.     for(i=0;i<10;i++) TestSet[52+i] = '0'+i;
  38.     TestSet[62] = '\0';
  39.    }
  40.  
  41.  /* check for loopback adapter */
  42.  SioRxClear(Port);
  43.  SioTxClear(Port);
  44.  SioPutc(Port,'$');
  45.  if( (char)GetChar(Port,500) != '$')
  46.    {DisplayLine("Loopback not detected. See Instructions.");
  47.     return FALSE;
  48.    }
  49.  
  50.  /* run the test */
  51.  wsprintf((LPSTR)Temp,"\n\rTest Run %d\n", ++TestRun);
  52.  DisplayLine(Temp);
  53.  wsprintf((LPSTR)Temp,"Test Set: %s",(LPSTR)TestSet);
  54.  DisplayString(Temp);
  55.  
  56.  /* send test sets */
  57.  DisplayString("\n\r  Sending set: ");
  58.  for(i=0;i<NbrRuns;i++)
  59.     {/* send test set again */
  60.      wsprintf((LPSTR)Temp,"%d ",i);
  61.      DisplayString(Temp);
  62.      for(n=0;n<TEST_SIZE;n++)
  63.         {c = TestSet[n];
  64.          SioPutc(Port,(char)c);
  65.         }
  66.     }
  67.  
  68.  /* receive test sets */
  69.  DisplayString("\n\rReceiving set: ");
  70.  for(i=0;i<NbrRuns;i++)
  71.     {/* receive next test set */
  72.      for(n=0;n<TEST_SIZE;n++)
  73.         {rc = GetChar(Port,1000);
  74.          if(rc<0)
  75.             {SioError(rc,"SioGetc:");
  76.              wsprintf((LPSTR)Temp,"%d bytes in COM%d RX queue\n", SioRxQue(Port),1+Port );
  77.              DisplayLine(Temp);
  78.              wsprintf((LPSTR)Temp,"%d bytes in COM%d TX queue\n", SioTxQue(Port),1+Port );
  79.              DisplayLine(Temp);
  80.              return FALSE;
  81.             }
  82.          /* compare character */
  83.          if((char)rc!=TestSet[n])
  84.            {wsprintf((LPSTR)Temp,"\n\rERROR: Expecting '%c'(0x%x), received '%c'(0x%x)\n",
  85.               (char)rc,(char)rc,TestSet[n],TestSet[n]);
  86.             DisplayLine(Temp);
  87.             return FALSE;
  88.            }
  89.         } /* end-for(n) */
  90.      wsprintf((LPSTR)Temp,"%d ",i);
  91.      DisplayString(Temp);
  92.     } /* end-for(i) */
  93.  
  94.  /* look at results */
  95.  DisplayLine("\n\rSUCCESS: Test AOK !");
  96.  return TRUE;
  97. }
  98.  
  99. int GetChar(int Port,int MilliSecs)
  100. {int   Code;
  101.  int   Flag;
  102.  DWORD Count;
  103.  Flag = 0;
  104.  while(1)
  105.    {Code = SioGetc(Port);
  106.     if(Code!=WSC_NO_DATA) return Code;
  107.     if(Flag==0)
  108.        {Count = GetTickCount() + (DWORD)MilliSecs;
  109.         Flag = 1;
  110.        }
  111.     if(GetTickCount()>Count) break;
  112.    }
  113.  return WSC_NO_DATA;
  114. }